HTMLify
240. Search a 2D Matrix II.java
Views: 1 | Author: cody
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | // 240. Search a 2D Matrix II java solution class Solution { public boolean searchMatrix(int[][] matrix, int target) { int i=0; int j=matrix[0].length-1; while( i<matrix.length && j>=0){ if(matrix[i][j]==target){ return true; }else if(matrix[i][j]>target){ j--; }else{ i++; } } return false; } } |